 package server.carnival;

 import client.MapleCharacter;
 import handling.channel.ChannelServer;
 import java.lang.ref.WeakReference;
 import java.util.Iterator;
 import java.util.LinkedList;
 import java.util.List;
 import server.maps.MapleMap;
 import tools.MaplePacketCreator;
 import tools.packet.UIPacket;

 public class MapleCarnivalParty
 {
/*  15 */   private final List<Integer> members = new LinkedList<>();
   private final WeakReference<MapleCharacter> leader;
   private final byte team;
   private final int channel;
/*  19 */   private short availableCP = 0; private short totalCP = 0;
   private boolean winner = false;

   public MapleCarnivalParty(MapleCharacter owner, List<MapleCharacter> members1, byte team1) {
/*  23 */     this.leader = new WeakReference<>(owner);
/*  24 */     for (MapleCharacter mem : members1) {
/*  25 */       this.members.add(Integer.valueOf(mem.getId()));
/*  26 */       mem.setCarnivalParty(this);
     }
/*  28 */     this.team = team1;
/*  29 */     this.channel = owner.getClient().getChannel();
   }

   public final MapleCharacter getLeader() {
/*  33 */     return this.leader.get();
   }

   public void addCP(MapleCharacter player, int ammount) {
/*  37 */     this.totalCP = (short)(this.totalCP + ammount);
/*  38 */     this.availableCP = (short)(this.availableCP + ammount);
/*  39 */     player.addCP(ammount);
   }

   public int getTotalCP() {
/*  43 */     return this.totalCP;
   }

   public int getAvailableCP() {
/*  47 */     return this.availableCP;
   }

   public void useCP(MapleCharacter player, int ammount) {
/*  51 */     this.availableCP = (short)(this.availableCP - ammount);
/*  52 */     player.useCP(ammount);
   }

   public List<Integer> getMembers() {
/*  56 */     return this.members;
   }

   public int getTeam() {
/*  60 */     return this.team;
   }

   public void warp(MapleMap map, String portalname) {
/*  64 */     for (Iterator<Integer> iterator = this.members.iterator(); iterator.hasNext(); ) { int chr = ((Integer)iterator.next()).intValue();
/*  65 */       MapleCharacter c = ChannelServer.getInstance(this.channel).getPlayerStorage().getCharacterById(chr);
/*  66 */       if (c != null) {
/*  67 */         c.changeMap(map, map.getPortal(portalname));
       } }

   }

   public void warp(MapleMap map, int portalid) {
/*  73 */     for (Iterator<Integer> iterator = this.members.iterator(); iterator.hasNext(); ) { int chr = ((Integer)iterator.next()).intValue();
/*  74 */       MapleCharacter c = ChannelServer.getInstance(this.channel).getPlayerStorage().getCharacterById(chr);
/*  75 */       if (c != null) {
/*  76 */         c.changeMap(map, map.getPortal(portalid));
       } }

   }

   public boolean allInMap(MapleMap map) {
/*  82 */     for (Iterator<Integer> iterator = this.members.iterator(); iterator.hasNext(); ) { int chr = ((Integer)iterator.next()).intValue();
/*  83 */       if (map.getCharacterById(chr) == null) {
/*  84 */         return false;
       } }

/*  87 */     return true;
   }

   public void removeMember(MapleCharacter chr) {
/*  91 */     for (int i = 0; i < this.members.size(); i++) {
/*  92 */       if (((Integer)this.members.get(i)).intValue() == chr.getId()) {
/*  93 */         this.members.remove(i);
/*  94 */         chr.setCarnivalParty(null);
       }
     }
   }


   public boolean isWinner() {
/* 101 */     return this.winner;
   }

   public void setWinner(boolean status) {
/* 105 */     this.winner = status;
   }

   public void displayMatchResult() {
/* 109 */     String effect = this.winner ? "quest/carnival/win" : "quest/carnival/lose";
/* 110 */     String sound = this.winner ? "MobCarnival/Win" : "MobCarnival/Lose";
/* 111 */     boolean done = false;
/* 112 */     for (Iterator<Integer> iterator = this.members.iterator(); iterator.hasNext(); ) { int chr = ((Integer)iterator.next()).intValue();
/* 113 */       MapleCharacter c = ChannelServer.getInstance(this.channel).getPlayerStorage().getCharacterById(chr);
/* 114 */       if (c != null) {
/* 115 */         c.send(UIPacket.showMapEffect(effect));
/* 116 */         c.send(MaplePacketCreator.playSound(sound));
/* 117 */         if (!done) {
/* 118 */           done = true;
/* 119 */           c.getMap().killAllMonsters(true);
/* 120 */           c.getMap().setSpawns(false);
         }
       }  }

   }
 }


/* Location:              C:\PGX\Server.jar!\server\carnival\MapleCarnivalParty.class
 * Java compiler version: 8 (52.0)
 * JD-Core Version:       1.1.3
 */